package cn.cxion.chat.app.login;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.appbar.AppBarLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTextChanged;
import cn.cxion.chat.R;
import cn.cxion.chat.app.activity.ConstantActivity;
import cn.cxion.chat.app.activity.RegisterActivity;
import cn.cxion.chat.app.constant.Constant;
import cn.cxion.chat.app.main.MainActivity;
import cn.cxion.chat.app.view.YEditText;
import cn.cxion.chat.kit.WfcBaseActivity;

public class LoginActivity2 extends WfcBaseActivity {


    @Bind(R.id.appbar)
    AppBarLayout appbar;
    @Bind(R.id.et_count)
    YEditText etCount;
    @Bind(R.id.et_password)
    YEditText etPassword;
    @Bind(R.id.tv_login)
    TextView tvLogin;
    @Bind(R.id.tv_register)
    TextView tvRegister;
    @Bind(R.id.tv_forger)
    TextView tvForger;

    @Override
    protected int contentLayout() {
        return R.layout.login_activity2;
    }

    private void hideStatusBar() {
        View decorView = getWindow().getDecorView();
        // Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }

    @Override
    protected void afterViews() {
        super.afterViews();
        hideStatusBar();
        ButterKnife.bind(this);
    }

    @OnTextChanged(value = R.id.et_count, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
    void inputPhoneNumber(Editable editable) {
        String phone = editable.toString().trim();
        if (phone.length() > 1) {
            tvLogin.setEnabled(true);
        } else {
            tvLogin.setEnabled(false);
        }
    }

    @OnTextChanged(value = R.id.et_password, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
    void inputAuthCode(Editable editable) {
        if (editable.toString().length() > 1) {
            tvLogin.setEnabled(true);
        } else {
            tvLogin.setEnabled(false);
        }
    }


    @OnClick({R.id.tv_login, R.id.tv_register,R.id.tv_forger})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_login:
                SharedPreferences sp = getSharedPreferences("config", Context.MODE_PRIVATE);
                sp.edit().putString("id", "3O8O4Oii")
                        .putString("userId",  "3O8O4Oii")
                        .putString("token", "mcDW1HKkUrIUinD0I6n0xOj/3phNImHl4RleRegHsbg7IpNE0U61pKYXQUQWILcIy30NiKmFVY7WHXao2NObox37q7EIbiP/+Ukd0IfrprhtXkZDbTvtbm5wud8p0eCJrpi1dUuq2G5R3/fQM4+n2wnbdxQSz7fxs9MaI38fWh8=")
                        .apply();
//                sp.edit().putString("id", "IxV6J6AA")
//                        .putString("token", "zgF9PB+KhV60Up4jUtRTWVRstrji+VW7iDUWJyPvLOeq/FFSo5mKBURj96XmFPwD26Rcl3tGyDvjqmyo2l0vJBzp0gCPyPu13cWx65b9LGiAzPus2lSydLSsF1y0CDSsSbBT1o2frjcv1iZpBkfI3xZlB/o/Mb7qgy+yRwPYHx8=")
//                        .apply();
//                3O8O4Oii
//                mcDW1HKkUrIUinD0I6n0xOj/3phNImHl4RleRegHsbg7IpNE0U61pKYXQUQWILcIy30NiKmFVY7WHXao2NObox37q7EIbiP/+Ukd0IfrprhtXkZDbTvtbm5wud8p0eCJrpi1dUuq2G5R3/fQM4+n2wnbdxQSz7fxs9MaI38fWh8=
//                IxV6J6AA
//                zgF9PB+KhV60Up4jUtRTWVRstrji+VW7iDUWJyPvLOeq/FFSo5mKBURj96XmFPwD26Rcl3tGyDvjqmyo2l0vJBzp0gCPyPu13cWx65b9LGiAzPus2lSydLSsF1y0CDSsSbBT1o2frjcv1iZpBkfI3xZlB/o/Mb7qgy+yRwPYHx8=
                Intent intent = new Intent(LoginActivity2.this, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                finish();
                break;
            case R.id.tv_register:
                Intent intent1 = new Intent(LoginActivity2.this, RegisterActivity.class);
                startActivity(intent1);
                break;
            case R.id.tv_forger:
                ConstantActivity.show(LoginActivity2.this,Constant.CHANGEPWD2);
                break;
        }
    }


}
